package cn.lin.controller;

import cn.lin.domain.Classroom;
import cn.lin.handler.EchoChannel;
import cn.lin.service.ClassRoomServiceYH;
import cn.lin.util.Result;
import cn.lin.vo.ClassRoomResourceVo;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/classRoom")
public class ClassRoomYH {

    @Autowired
    private ClassRoomServiceYH classRoomServiceYH;

    @GetMapping("/classList")
    public Result<List> findClass(@RequestParam("classId") int classId){
        System.out.println("classId= "+classId);
        List<Classroom> classList = classRoomServiceYH.findClass(classId);
        Result result = new Result<>();
        if(classList.size()!=0){
            result.setCode(1001);
            result.setMsg("数据查询成功！");
            result.setT(classList);
        }else{
            result.setCode(1001);
            result.setMsg("没有查询到相关的课程!");
        }
        return result;
    }

    @PostMapping("/getClassResource")
    public Object getClassResource(@RequestBody List<Integer> catalogIdList){
        Map<Integer, List<ClassRoomResourceVo>> classResource = classRoomServiceYH.findClassResource(catalogIdList);
        if (classResource!=null){
            return Result.ok("课堂资源获取成功",classResource) ;
        }else {
            return Result.error("查询失败");
        }
    }

    @GetMapping("/getClassResourceId")
    public Object getClassResourceId(@RequestParam("classroomId") Integer classroomId){
        List<Integer> fileId = classRoomServiceYH.getFileId(classroomId);

        if (fileId==null){
            return Result.error("查询失败");
        }else {
            return fileId ;
        }
    }


}
